﻿using System;
using System.Windows.Forms;

namespace NoteHelper.BaseControl
{
    public partial class Searchbar : UserControl
    {
        public Action<string> ExecuteSearch;

        public Searchbar()
        {
            InitializeComponent();
        }

        public string SearchText
        {
            get { return txtSearch.Text.Trim(); }
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            string cmd = txtSearch.Text.Trim().Replace('：', ':');
            txtSearch.Text = "";
            if (ExecuteSearch == null)
            {
                AlterMsg.Info("未绑定查询方法");
            }
            else
            {
                ExecuteSearch(cmd);
            }
        }

        private void txtSearch_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btnSearch_Click(sender, e);
        }
    }
}
